package com.itheima.admin.controller;

import com.itheima.admin.pojo.AdChannel;
import com.itheima.common.vo.PageResultVo;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.service.AdChannelService;
import com.itheima.core.controller.AbstractCoreController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/channel")
@Api(tags = "频道管理")
public class AdChannelController extends AbstractCoreController<AdChannel> {


    private AdChannelService adChannelService;
    @Autowired
    public AdChannelController(AdChannelService adChannelService) {
        super(adChannelService);
        this.adChannelService = adChannelService;
    }

    /**
     * 频道分页查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("频道分页查询")
    public PageResultVo<AdChannel> pageList(@RequestBody ChannelPageRequestDto dto){
        PageResultVo<AdChannel> pageResultVo = adChannelService.pageList(dto);
        return pageResultVo;
    }

  /*  *//**
     * 新增频道
     * @param adChannel
     * @return
     *//*
    @PostMapping("/save")
    @ApiOperation("新增频道")
    public ResultVo save(@RequestBody AdChannel adChannel){
        if(null == adChannel){
            return ResultVo.error(HttpCodeEnum.PARAM_REQUIRE);
        }
        //NPE 空指针
        adChannel.setIsDefault(false);
        adChannel.setCreatedTime(new Date());
        if (adChannelService.save(adChannel)) {
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    *//**
     * 查询
     * @param id
     * @return
     *//*
    @GetMapping("/{id}")
    @ApiOperation("通过id查询频道")
    public ResultVo findById(@PathVariable Integer id){
        return ResultVo.ok(adChannelService.getById(id));
    }

    *//**
     * 更新频道
     * @param adChannel
     * @return
     *//*
    @PostMapping("/update")
    @ApiOperation("更新频道")
    public ResultVo update(@RequestBody AdChannel adChannel){
        if (null == adChannel && null == adChannel.getId()){
            return ResultVo.error(HttpCodeEnum.PARAM_REQUIRE);
        }
        adChannel.setIsDefault(false);
        adChannel.setCreatedTime(new Date());
        if (adChannelService.updateById(adChannel)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    *//**
     * 删除频道
     * @param id
     * @return
     *//*
    @DeleteMapping("/del/{id}")
    @ApiOperation("删除频道")
    public ResultVo del(@PathVariable Integer id){
        if (adChannelService.removeById(id)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }*/

}

